<?php
namespace app\common\service\lib;


use EasyAdmin\upload\driver\alioss\Oss;

class UploadFile
{

    public static function upFile($file)
    {
        $name = time() . rand(123,456) . '.jpg';
        $config = [
            'alioss_access_key_id' => config('setting.aliyun.accessKeyId'),
            'alioss_access_key_secret' => config('setting.aliyun.accessKeySecret'),
            'alioss_endpoint' => config('setting.aliyun.alioss_endpoint'),
            'alioss_bucket' => config('setting.aliyun.alioss_bucket'),
            'alioss_domain' => config('setting.aliyun.alioss_domain'),
        ];
        $oss = Oss::instance($config);
        $oss->save($name,$file);
        $pathFile = config('setting.aliyun.alioss_domain') . "/$name";
        return $pathFile;
    }


    public static function cardUpload($file)
    {
        $name = time() . rand(100,999) . '.jpg';
        $config = [
            'alioss_access_key_id' => config('setting.aliyun.accessKeyId'),
            'alioss_access_key_secret' => config('setting.aliyun.accessKeySecret'),
            'alioss_endpoint' => config('setting.aliyun.alioss_endpoint'),
            'alioss_bucket' => config('setting.aliyun.alioss_bucket'),
            'alioss_domain' => config('setting.aliyun.alioss_domain'),
        ];
        $oss = Oss::instance($config);
        $oss->save($name,$file);
        $pathFile = config('setting.aliyun.alioss_orginal_domain') . "/$name";
        return $pathFile;
    }
}



